<?php

class Controller_Auth extends Controller_Template
{
	protected $template = 'auth/template';

	public function actionSignin()
	{
		$this->template->title = $this->settings['title'];
		$form = new Form('signin', 'Sign in');
		$form->text('username', 'Name')->rule('maxLength', 16)->attribute('size', 24)->rule('required');
		$form->password('password', 'Password')->rule('maxLength', 32)->attribute('size', 24)->rule('required');
		$form->checkbox('persistent', '', 'Stay signed in');
		$form->submit('submit', 'Sign In');
		if (Request::$method == 'POST') {
			if ($form->validate()) {
				$values = $form->getValues();
				if (Auth::getInstance()->authenticate($values['username'], $values['password'], $values['persistent'])) {
					$this->response->redirect('/admin/');
				} else {
					$this->template->error = 'Your attempt has failed.';
				}
			}
		}

		$this->template->content = $form;
	}

	public function actionSignout()
	{
		Auth::getInstance()->clearIdentity();
		$this->response->redirect('/admin/');
	}
}
?>